# 9. 伐木工

9

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (line) => {
    let len = parseInt(line);
    const dp = new Array(len+1).fill(0);
    const times = new Array(len+1).fill(0);
    const lastCut = new Array(len+1).fill(0);

    for(let i=1; i<=len; i++) {
        dp[i] = lastCut[i] = i;
        for(let j=1; j<i; i++) {
            const product = dp[i - j] * j;
            if (product > dp[i]) {
                dp[i] = product;
                lastCut[i] = j;
                times[i] = time[i - j] + 1;
            } else if(product === dp[i] && time[i] > time[i-j]+1) {
                lastCut[i] = j;
                time[i] = time[i - j] + 1;
            }
        }
    }

    let res = [];
    while(len > 0) {
        res.push(lastCut[len]);
        len -= lastCut[len];
    }
    res.sort((a,b) => a-b);
    console.log(res.join(' '));
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35